package com.example.springbootweb01.controller;


import com.example.springbootweb01.pojo.User;
import com.example.springbootweb01.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileNotFoundException;
import java.util.List;


//@RestController
//public class UserController {
//    @RequestMapping("/list")
//    public  List<User> list() throws FileNotFoundException {
//        //1.加载用户信息，获取用户数据
//        //InputStream in = new FileInputStream(new File("D:\\web\\untitled\\springboot-web-01\\src\\main\\resources\\user.txt"));
//     InputStream in  = this.getClass().getClassLoader().getResourceAsStream("user.txt");
//        ArrayList<String> lines = IoUtil.readLines(in, StandardCharsets.UTF_8,new ArrayList<>());
//
//        //2.解析用户信息，封装User对象
//List<User> usersList = lines.stream().map(line->{
//    String[] parts = line.split(",");
//    Integer id = Integer.parseInt(parts[0]);
//    String username = parts[1];
//    String password = parts[2];
//    String name = parts[3];
//    Integer age = Integer.parseInt(parts[4]);
//    LocalDateTime updataTime = LocalDateTime.parse((parts[5]), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//    return new User(id,username,password,name,age,updataTime);
//}).toList();
//
//        //3.返回用户信息（JSON）
//      return usersList;
//    }
//}
@RestController
public class UserController {
//    @Qualifier("userServiceimpl")
//    @Autowired
//    private UserService userService;
@Resource(name = "userServiceimpl02")
    private UserService userService;
    @RequestMapping("/list")
    public List<User> list() throws FileNotFoundException {
        //1.加载用户信息，获取用户数据
        //InputStream in = new FileInputStream(new File("D:\\web\\untitled\\springboot-web-01\\src\\main\\resources\\user.txt"));

        List<User> usersList = userService.findAll();


        //3.返回用户信息（JSON）
        return usersList;
    }
}
